package com.ordersystem.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author : asus1020
 * @version : [v1.0]
 * @className : UploadFileUtils
 * @description : [描述说明该类的功能]
 * @createTime : [2022/3/31 14:55]
 * @updateUser : asus1020
 * @updateTime : [2022/3/31 14:55]
 * @updateRemark : [描述说明本次修改内容]
 */

@Component
public class UploadFileUtils {
    @Value("${imageUrl}")
    private String imageUrl;
    //服务器访问地址前缀
    @Value("${realUrl}")
    private String realUrlPre;
    //文件上传
   public  String uploadImg(InputStream fileInputStream,String fileName) throws IOException {
       FileOutputStream fileOutputStream = new FileOutputStream(new File(imageUrl + fileName));
       byte[]lens=new byte[1024*8];
       int len=0;
       while ((len=fileInputStream.read(lens,0,lens.length))!=-1){
           fileOutputStream.write(lens,0,len);
       }
       return realUrlPre+fileName;
   }
}
